<?php

namespace app\task\controller;

use app\task\logic\TaskLogic;

/**
 * 定制任务api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/09/12
 * Time: 19:10
 */
class Task extends Base
{
    public function __construct()
    {
        parent::__construct();
        $this->t_logic = new TaskLogic();
    }

    public function minute()
    {
        //处理当天日期节假日信息
        $dcb = new DealHoliday();
        $r = $dcb->deal_holiday();
        echo $r->getContent() . "\n";

        //处理社区巡店分部
        $dcb = new DealCpBranch();
        $r = $dcb->deal_cp_branch();
        echo $r->getContent() . "\n";

        //处理社区巡店分部知错能改
        $dm = new DealMistake();
        $r = $dm->deal_cp_branch_mistake();
        echo $r->getContent() . "\n";

        //处理事项超时知错能改
        $r = $dm->deal_matter_out_time_mistake();
        echo $r->getContent() . "\n";

        //处理社区巡店用户报表（月）
        $cfum = new CpFormUserMonth();
        $r = $cfum->deal_form();
        echo $r->getContent() . "\n";

        //处理社区巡店分部报表（月）
        $cfbm = new CpFormBranchMonth();
        $r = $cfbm->deal_form();
        echo $r->getContent() . "\n";

        //处理工作记录部门报表（天）
        $wfdd = new WrFormDepartmentDay();
        $r = $wfdd->deal_form();
        echo $r->getContent() . "\n";

        //处理工作圈消息置顶超时
        $dwc = new DealWorkCircle();
        $r = $dwc->deal_wc_is_top();
        echo $r->getContent() . "\n";

        //处理积分扣分
        $r = $this->deal_integral();

        //处理生成工位小程序码
        $dws = new DealWorkStation();
        $r = $dws->deal_gen_ws_mini_code();
        echo $r->getContent() . "\n";

        //获取access_token
        $w = new Wechat();
        $r = $w->deal_access_token();
        echo $r->getContent() . "\n";

        return json($this->t_logic->get_response(1, 'OK'));
    }

    /**
     * 处理积分扣分
     * @return \think\response\Json
     */
    public function deal_integral()
    {
        $deal_date = date('Y-m-d', strtotime('-1 day'));
        $di = new DealIntegral();

        //处理未完成社区巡店积分
        $r = $di->deal_no_cp_integral($deal_date);
        echo $r->getContent() . "\n";

        //处理未发布推广工作积分
        $r = $di->deal_no_re_integral($deal_date);
        echo $r->getContent() . "\n";

        //处理事项超时积分
        $r = $di->deal_otm_integral();
        echo $r->getContent() . "\n";

        return json($this->t_logic->get_response(1, '处理积分扣定时人数'));
    }
}
